{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 5.11 \u6587\u4ef6\u8def\u5f84\u540d\u7684\u64cd\u4f5c\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u9700\u8981\u4f7f\u7528\u8def\u5f84\u540d\u6765\u83b7\u53d6\u6587\u4ef6\u540d\uff0c\u76ee\u5f55\u540d\uff0c\u7edd\u5bf9\u8def\u5f84\u7b49\u7b49\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f7f\u7528 os.path \u6a21\u5757\u4e2d\u7684\u51fd\u6570\u6765\u64cd\u4f5c\u8def\u5f84\u540d\u3002\n\u4e0b\u9762\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u4f8b\u5b50\u6765\u6f14\u793a\u4e00\u4e9b\u5173\u952e\u7684\u7279\u6027\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import os\npath = '/Users/beazley/Data/data.csv'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Get the last component of the path\nos.path.basename(path)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Get the directory name\nos.path.dirname(path)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Join path components together\nos.path.join('tmp', 'data', os.path.basename(path))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Expand the user's home directory\npath = '~/Data/data.csv'\nos.path.expanduser(path)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Split the file extension\nos.path.splitext(path)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5bf9\u4e8e\u4efb\u4f55\u7684\u6587\u4ef6\u540d\u7684\u64cd\u4f5c\uff0c\u4f60\u90fd\u5e94\u8be5\u4f7f\u7528 os.path \u6a21\u5757\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u6807\u51c6\u5b57\u7b26\u4e32\u64cd\u4f5c\u6765\u6784\u9020\u81ea\u5df1\u7684\u4ee3\u7801\u3002\n\u7279\u522b\u662f\u4e3a\u4e86\u53ef\u79fb\u690d\u6027\u8003\u8651\u7684\u65f6\u5019\u66f4\u5e94\u5982\u6b64\uff0c\n\u56e0\u4e3a os.path \u6a21\u5757\u77e5\u9053Unix\u548cWindows\u7cfb\u7edf\u4e4b\u95f4\u7684\u5dee\u5f02\u5e76\u4e14\u80fd\u591f\u53ef\u9760\u5730\u5904\u7406\u7c7b\u4f3c Data/data.csv\n\u548c Data\\data.csv \u8fd9\u6837\u7684\u6587\u4ef6\u540d\u3002\n\u5176\u6b21\uff0c\u4f60\u771f\u7684\u4e0d\u5e94\u8be5\u6d6a\u8d39\u65f6\u95f4\u53bb\u91cd\u590d\u9020\u8f6e\u5b50\u3002\u901a\u5e38\u6700\u597d\u662f\u76f4\u63a5\u4f7f\u7528\u5df2\u7ecf\u4e3a\u4f60\u51c6\u5907\u597d\u7684\u529f\u80fd\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8981\u6ce8\u610f\u7684\u662f os.path \u8fd8\u6709\u66f4\u591a\u7684\u529f\u80fd\u5728\u8fd9\u91cc\u5e76\u6ca1\u6709\u5217\u4e3e\u51fa\u6765\u3002\n\u53ef\u4ee5\u67e5\u9605\u5b98\u65b9\u6587\u6863\u6765\u83b7\u53d6\u66f4\u591a\u4e0e\u6587\u4ef6\u6d4b\u8bd5\uff0c\u7b26\u53f7\u94fe\u63a5\u7b49\u76f8\u5173\u7684\u51fd\u6570\u8bf4\u660e\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}